﻿using System.Collections.Generic;
using System.Web.Mvc;
using BlogLite.Controllers;
using BlogLite.Models.Database;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BlogLite.Tests.Controllers
{
    [TestClass]
    public class HomeControllerTest : HomeControllerTestContext
    {
        [TestMethod]
        public void Index_ViewModel_IsInstanceOfTypePost()
        {            
            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(List<Post>));
        }

        [TestMethod]
        public void Error()
        {           
            // Act
            ViewResult result = controller.Error() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        public void Error404()
        {
            // Act
            ViewResult result = controller.Error404() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        public void GetPost_PostIsNull_RedirectsToError404()
        {
            // Act
            RedirectToRouteResult result = controller.Post(404) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Error404", result.RouteValues["action"]);
        }

        [TestMethod]
        public void GetPost_PostIsNotNull_ModelIsInstanceOfTypePost()
        {
            // Act
            ViewResult result = controller.Post(1) as ViewResult;

            // Assert
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Post));
        }
    }
}
